<template>
	<view class="content">
			<view class="postings">
				<view class="post_con">
					<text>库存仓库</text>
					<text>{{nullStr(data.warehouse)}}</text>
				</view>
				<view class="post_con">
					<text>物资名称</text>
					<text>{{nullStr(data.materialName)}}</text>
				</view>
				<view class="post_con">
					<text>规格型号</text>
					<text>{{nullStr(data.standards)}}</text>
				</view>
				<view class="post_con">
					<text>单位</text>
					<text>{{nullStr(data.unitName)}}</text>
				</view>
				<view class="post_con">
					<text>库存数量</text>
					<text>{{nullStr(data.quantity)}}</text>
				</view>
				<view class="post_con">
					<text>单价（元）</text>
					<text>{{nullStrZ(data.unitPrice)}}</text>
				</view>
				<view class="post_con">
					<text>总计金额（元）</text>
					<text>{{nullStrZ(data.totalPrice)}}</text>
				</view>
				<view class="post_con post_col">
					<text>用途</text>
					<text>{{nullStr(data.purpose)}}</text>
				</view>
				<view class="post_con post_col">
					<text>备注</text>
					<text>{{nullStr(data.remark)}}</text>
				</view>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				data:{},
				dictList:[]
			};
		},
		onLoad(option) {
			this.id = option.id
			this.getDict();
			this.getTitle(option.name)
			this.getInfo()
		},
		methods: {
			getDict() {
				//联网加载数据
				this.apis.commonApi
					.getDict("unit_type")
					.then((res) => {
						this.dictList = res.data;
					})
					.catch(() => {
						//联网失败的回调,隐藏下拉刷新的状态
					});
			},
			getTitle(title) {
				uni.setNavigationBarTitle({
					title: title
				});
			},

			getInfo() {
				let that = this
				//联网加载数据
				console.log("this.id",this.id);
				this.apis.materialsApi.maMaterial(this.id).then(res => {
					this.data = res.data
					const house=res.data.houseQuantityList
					let quantity=0
					let warehouse=[]
				    for (let i = 0; i < house.length; i++) {
					  quantity+=house[i].quantity
					  warehouse.push(house[i].warehouse)
				    }

						that.dictList.forEach((itemType) => {
							if (itemType.dictValue == this.data.unit) {
								this.data.unitName = itemType.dictLabel;
							}
						});
				    this.data.quantity=quantity
				    this.data.warehouse=warehouse.join(',')
					this.data.unitPrice=(this.data.unitPrice===null?0:this.data.unitPrice*quantity)
				}).catch(() => {
					//联网失败的回调,隐藏下拉刷新的状态
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
$subheadColor:#111111;
$titleColor:#333333;
@mixin boldTitle {
	font-size: 28rpx;
	font-weight: 500;
	color: #666666;
}
@mixin  bordcon {
	font-size: 28rpx;
	font-weight: 500;
	color: #333333;
}
@mixin  padding {
			padding: 30rpx 0;
}
.content{
	padding: 20rpx;
	box-sizing: border-box;
	.postings{
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
		padding: 0 32rpx;
		margin-bottom: 20rpx;
		box-sizing: border-box;
		border-radius: 12rpx;
		.post_title{
			@include bordcon
			@include padding
		}
		.post_con{
			display: flex;
			justify-content: space-between;
			border-bottom: 1rpx solid #EEEEEE;
			@include padding
			text:nth-child(1){
				@include boldTitle
			}
			text:nth-child(2){
				@include bordcon
			}
		}
		.post_col{
			display: flex;
			flex-direction: column;
			text:nth-child(1){
				margin-bottom: 20rpx;
			}
		}
		view:last-child{
			border-bottom: none;
		}
	}
}
</style>
